package com.fz.us.oa.core.dao.com.impl;

import com.fz.us.admin.company.dao.impl.BaseFlowDaoImpl;
import com.fz.us.base.bean.BaseEnum;
import com.fz.us.oa.core.dao.com.PerformDetailDao;
import com.fz.us.oa.core.entity.com.ContractPerform;
import com.fz.us.oa.core.entity.com.PerformDetail;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

/**
 * Created by dzw on 2017/12/4.
 */
@Repository
public class PerformDetailDaoImpl extends BaseFlowDaoImpl<PerformDetail, String> implements PerformDetailDao {
    @Override
    public BigDecimal getPerformNum(ContractPerform contractPerform, String type) {
        Object num=getSession().createQuery("select sum(p.money) from PerformDetail p where p.type=? and p.contractPerform=? and p.state=?")
                .setParameter(0, type)
                .setParameter(1, contractPerform)
                .setParameter(2, BaseEnum.StateEnum.Enable)
                .uniqueResult();
        return num==null?new BigDecimal(0):new BigDecimal(num.toString());
    }
}
